<template>
  <div class="footer">
    <div class="all_select">
      <label class="cl-checkbox">
        <!-- <input type="checkbox" :checked="isAll" @change="selectAllElement()"/> -->
        <input type="checkbox" v-model="isAll"/>
        <span></span>
      </label>
      <span>全选({{ setTodosFooter }}/{{ lengths }})</span>
    </div>
    <div>
      <button @click="deleteAllSelect()">删除选择的</button>
    </div>
  </div>
</template>

<script>
export default {
  name: "TodoListFooter", 
  methods:{
    deleteAllSelect(){
      this.$emit('deleteSelect');
    }
  },
  computed: {
    setTodosFooter() {
      return this.todoArr.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0);
    },
    lengths() {
      return this.todoArr.length;
    },
    isAll:{
      get(){
        return this.setTodosFooter === this.lengths && this.lengths > 0;
      },
      set(v){
        this.checkIsDone(v)
        // console.log(this);
      }
    },
  },
  props: ["todoArr",'checkIsDone','deleteSelect'],
};
</script>

<style lang="scss" scoped>
.footer {
  width: 100%;
  height: 8%;
  //   background-color: bisque;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.all_select {
  display: flex;
  justify-content: center;
  align-items: center;
}
.check {
  display: flex;
}
.title {
  margin-left: 10px;
}
.cl-checkbox {
  position: relative;
  display: inline-block;
}

/* Input */
.cl-checkbox > input {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  z-index: -1;
  position: absolute;
  left: -10px;
  top: -8px;
  display: block;
  margin: 0;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  background-color: rgba(0, 0, 0, 0.6);
  box-shadow: none;
  outline: none;
  opacity: 0;
  transform: scale(1);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.2s;
}

/* Span */
.cl-checkbox > span {
  display: inline-block;
  width: 100%;
  cursor: pointer;
}

/* Box */
.cl-checkbox > span::before {
  content: "";
  display: inline-block;
  box-sizing: border-box;
  margin: 3px 11px 3px 1px;
  border: solid 2px;
  /* Safari */
  border-color: rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  width: 18px;
  height: 18px;
  vertical-align: top;
  transition: border-color 0.2s, background-color 0.2s;
}

/* Checkmark */
.cl-checkbox > span::after {
  content: "";
  display: block;
  position: absolute;
  top: 3px;
  left: 1px;
  width: 10px;
  height: 5px;
  border: solid 2px transparent;
  border-right: none;
  border-top: none;
  transform: translate(3px, 4px) rotate(-45deg);
}
/* Checked, Indeterminate */
.cl-checkbox > input:checked,
.cl-checkbox > input:indeterminate {
  background-color: #018786;
}
.cl-checkbox > input:checked + span::before,
.cl-checkbox > input:indeterminate + span::before {
  border-color: #018786;
  background-color: #018786;
}
.cl-checkbox > input:checked + span::after,
.cl-checkbox > input:indeterminate + span::after {
  border-color: #fff;
}
.cl-checkbox > input:indeterminate + span::after {
  border-left: none;
  transform: translate(4px, 3px);
}
/* Hover, Focus */
.cl-checkbox:hover > input {
  opacity: 0.04;
}
.cl-checkbox > input:focus {
  opacity: 0.12;
}
.cl-checkbox:hover > input:focus {
  opacity: 0.16;
}
/* Active */
.cl-checkbox > input:active {
  opacity: 1;
  transform: scale(0);
  transition: transform 0s, opacity 0s;
}
.cl-checkbox > input:active + span::before {
  border-color: #85b8b7;
}
.cl-checkbox > input:checked:active + span::before {
  border-color: transparent;
  background-color: rgba(0, 0, 0, 0.6);
}
/* Disabled */
.cl-checkbox > input:disabled {
  opacity: 0;
}
.cl-checkbox > input:disabled + span {
  color: rgba(0, 0, 0, 0.38);
  cursor: initial;
}
.cl-checkbox > input:disabled + span::before {
  border-color: currentColor;
}
.cl-checkbox > input:checked:disabled + span::before,
.cl-checkbox > input:indeterminate:disabled + span::before {
  border-color: transparent;
  background-color: currentColor;
}
button {
  //   width: 70px;
  padding: 8px 8px;
  height: 35px;
  outline: none;
  background-color: rgba(255, 0, 0, 0.8);
  border: 1px solid transparent;
  color: white;
  white-space: nowrap;
  text-align: center;
  font-size: 14px;
  border-radius: 3px;
  cursor: pointer;
  transition: 0.3s;
}
button:hover {
  background-color: rgba(255, 0, 0, 0.4);
}
</style>